'''
https://leetcode.cn/problems/print-immutable-linked-list-in-reverse
'''


# """
# This is the ImmutableListNode's API interface.
# You should not implement it, or speculate about its implementation.
# """
class ImmutableListNode:
    def printValue(self) -> None:
        # print the value of this node.
        pass
    def getNext(self) -> 'ImmutableListNode':
        # return the next node.
        return self

class Solution:
    def printLinkedListInReverse(self, head: 'ImmutableListNode') -> None:
        # temp = []
        # cur = head
        # while cur:
        #     temp.append(cur)
        #     cur = cur.getNext()
        # for node in reversed(temp):
        #     node.printValue()
        if not head:
            return
        self.printLinkedListInReverse(head.getNext())
        head.printValue()